home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / sossnt.zip / SOSSNT / RPC / SVC_AUTH.C < prev    next >
C/C++ Source or Header  |  1993-03-06  |  4KB  |  119 lines

  1. /*
  2.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  3.  * unrestricted use provided that this legend is included on all tape
  4.  * media and as a part of the software program in whole or part.  Users
  5.  * may copy or modify Sun RPC without charge, but are not authorized
  6.  * to license or distribute it to anyone else except as part of a product or
  7.  * program developed by the user.
  8.  * 
  9.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  10.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  11.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  12.  * 
  13.  * Sun RPC is provided with no support and without any obligation on the
  14.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  15.  * modification or enhancement.
  16.  * 
  17.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  18.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  19.  * OR ANY PART THEREOF.
  20.  * 
  21.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  22.  * or profits or other special, indirect and consequential damages, even if
  23.  * Sun has been advised of the possibility of such damages.
  24.  * 
  25.  * Sun Microsystems, Inc.
  26.  * 2550 Garcia Avenue
  27.  * Mountain View, California  94043
  28.  */
  29. #ifndef lint
  30. static char sccsid[] = "@(#)svc_auth.c 1.1 86/02/03 Copyr 1984 Sun Micro";
  31. #endif
  32.  
  33. /*
  34.  * svc_auth.c, Server-side rpc authenticator interface.
  35.  *
  36.  * Copyright (C) 1984, Sun Microsystems, Inc.
  37.  */
  38.  
  39. #include <winsock.h>
  40. #include "types.h"
  41. /* #include "in.h" */
  42. #include "xdr.h"
  43. #include "auth.h"
  44. #include "clnt.h"
  45. #include "rpc_msg.h"
  46. #include "svc.h"
  47. #include "svc_auth.h"
  48.  
  49. /*
  50.  * svcauthsw is the bdevsw of server side authentication. 
  51.  * 
  52.  * Server side authenticators are called from authenticate by
  53.  * using the client auth struct flavor field to index into svcauthsw.
  54.  * The server auth flavors must implement a routine that looks  
  55.  * like: 
  56.  * 
  57.  *    enum auth_stat 
  58.  *    flavorx_auth(rqst, msg)
  59.  *        register struct svc_req *rqst; 
  60.  *        register struct rpc_msg *msg;
  61.  *  
  62.  */
  63.  
  64. enum auth_stat _svcauth_null();        /* no authentication */
  65. enum auth_stat _svcauth_unix();        /* unix style (uid, gids) */
  66. enum auth_stat _svcauth_short();    /* short hand unix style */
  67.  
  68. static struct {
  69.     enum auth_stat (*authenticator)();
  70. } svcauthsw[] = {
  71.     _svcauth_null,            /* AUTH_NULL */
  72.     _svcauth_unix,            /* AUTH_UNIX */
  73.     _svcauth_short            /* AUTH_SHORT */
  74. };
  75. #define    AUTH_MAX    2        /* HIGHEST AUTH NUMBER */
  76.  
  77.  
  78. /*
  79.  * The call rpc message, msg has been obtained from the wire.  The msg contains
  80.  * the raw form of credentials and verifiers.  authenticate returns AUTH_OK
  81.  * if the msg is successfully authenticated.  If AUTH_OK then the routine also
  82.  * does the following things:
  83.  * set rqst->rq_xprt->verf to the appropriate response verifier;
  84.  * sets rqst->rq_client_cred to the "cooked" form of the credentials.
  85.  *
  86.  * NB: rqst->rq_cxprt->verf must be pre-alloctaed;
  87.  * its length is set appropriately.
  88.  *
  89.  * The caller still owns and is responsible for msg->u.cmb.cred and
  90.  * msg->u.cmb.verf.  The authentication system retains ownership of
  91.  * rqst->rq_client_cred, the cooked credentials.
  92.  */
  93. enum auth_stat
  94. _authenticate(rqst, msg)
  95.     struct svc_req *rqst;
  96.     struct rpc_msg *msg;
  97. {
  98.     int cred_flavor;
  99.  
  100.     rqst->rq_cred = msg->rm_call.cb_cred;
  101.     rqst->rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor;
  102.     rqst->rq_xprt->xp_verf.oa_length = 0;
  103.     cred_flavor = rqst->rq_cred.oa_flavor;
  104.     if (cred_flavor <= AUTH_MAX) {
  105.         return ((*(svcauthsw[cred_flavor].authenticator))(rqst, msg));
  106.     }
  107.  
  108.     return (AUTH_REJECTEDCRED);
  109. }
  110.  
  111. enum auth_stat
  112. _svcauth_null(/*rqst, msg*/)
  113.     /*struct svc_req *rqst;
  114.     struct rpc_msg *msg;*/
  115. {
  116.  
  117.     return (AUTH_OK);
  118. }
  119.